-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Fix DisposeAsync pattern: remove incorrect Dispose(false) call #50900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: gewarren <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR corrects the DisposeAsync pattern documentation by removing an incorrect Dispose(false) call that was shown in both the documentation and code examples. The Dispose(bool disposing) pattern with false is intended for finalizer contexts, not for DisposeAsync() implementations. The PR also adds the missing .ConfigureAwait(false) to align with best practices.
- Removes unnecessary and incorrect
Dispose(false)call fromDisposeAsync()method - Adds
.ConfigureAwait(false)to theDisposeAsyncCore()await call in the documentation example - Removes the explanatory NOTE that incorrectly justified calling
Dispose(false)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
docs/standard/garbage-collection/implementing-disposeasync.md |
Corrects the DisposeAsync() pattern example by removing the incorrect Dispose(false) call, adding .ConfigureAwait(false), and removing the misleading NOTE that explained the incorrect pattern |
docs/standard/garbage-collection/snippets/dispose-async/ExampleConjunctiveDisposable.cs |
Removes the incorrect Dispose(false) call from the DisposeAsync() method implementation to match the corrected pattern |
The documentation incorrectly showed
Dispose(false)being called fromDisposeAsync(). This is unnecessary—DisposeAsync()is not a finalizer context, and all cleanup is already handled inDisposeAsyncCore().Changes
Dispose(false)call and explanatory NOTE from example; added missing.ConfigureAwait(false)Dispose(false)call fromDisposeAsync()implementationCorrect Pattern
The
Dispose(bool disposing)pattern belongs to synchronous disposal with finalizers, not async disposal.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
Internal previews